package com.jinyi.wwdeng.ui.tab

import android.graphics.Typeface
import androidx.recyclerview.widget.RecyclerView
import cn.bingoogolapple.baseadapter.BGARecyclerViewAdapter
import cn.bingoogolapple.baseadapter.BGAViewHolderHelper
import com.jinyi.wwdeng.R
import org.json.JSONObject

class TabAdapter(recyclerView: RecyclerView?) :
    BGARecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_tab) {

    override fun setItemChildListener(helper: BGAViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    override fun fillData(helper: BGAViewHolderHelper, position: Int, model: JSONObject) {
        val isSelect = model.optBoolean("isSelect", false)
        var tabImage = helper.getImageView(R.id.tabImage)
        var tabText = helper.getTextView(R.id.tabTitle)
        tabText.text = mContext.getString(model.optInt("tabTitle"))

        if (isSelect) {
            tabText.setTypeface(Typeface.DEFAULT,Typeface.BOLD)
            tabImage.setImageResource(model.optInt("tabSelectRes"))
        } else {
            tabText.setTypeface(Typeface.DEFAULT,Typeface.NORMAL)
            tabImage.setImageResource(model.optInt("tabNormalRes"))
        }
    }
}